#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : Book.py
# @Author: Xuhao
# @Date  : 2018/3/16
# @Desc  :

from flask_restful import Resource
from flask import request
from flask_restful import reqparse, abort
from app.Modules.feedback_modules import Feedback
from flask import jsonify
import json


class FeedBackList(Resource):
    def get(self):

        ret = Feedback.fetch_feedback()

        if ret != None:
            return jsonify({'error_code': 0,
                            'data': json.loads(ret)})
        else:
            return {'error_code': 1001,
                    'data': ret}

class AddFeedBack(Resource):
    def post(self):
        jsondata = request.form.to_dict()
        content = jsondata['content']
        title = jsondata['title']

        ret = Feedback.add_feedback(title=title, content=content)

        return {'error_code': 0,
                'message': '添加成功',
                'data': ''}